#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>

// 下面的内容应该在头文件中定义，这里为了演示方便直接放在.c文件中
EFI_GUID gEfiDriverTestGuid = { 0x2afceb91, 0x88f2, 0x4f91, { 0xb0, 0x5e, 0x7f, 0x43, 0x1a, 0xec, 0xfd, 0x52 } };

typedef 
EFI_STATUS
(*DRIVER_TEST)(VOID);

typedef struct _EFI_DRIVER_TEST_PROTOCOL
{
    DRIVER_TEST PrintHelloWorld;
} EFI_DRIVER_TEST_PROTOCOL;

////////////////////////////////////////////////////////////////////////////////////////////

EFI_STATUS
EFIAPI
UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE  *SystemTable)
{
    EFI_STATUS Status;
    EFI_DRIVER_TEST_PROTOCOL *DriverTest;

    // 查找协议
    Status = gBS->LocateProtocol(&gEfiDriverTestGuid, NULL, (VOID**)&DriverTest);
    if (EFI_ERROR(Status)) {
        Print(L"LocateProtocol failed: %r\n", Status);
        return Status;
    }

    // 调用协议中的函数
    Status = DriverTest->PrintHelloWorld();
    if (EFI_ERROR(Status)) {
        Print(L"PrintHelloWorld failed: %r\n", Status);
        return Status;
    }

    return EFI_SUCCESS;
}